package io.renren.modules.common.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import io.renren.modules.common.dao.EducationDao;
import io.renren.modules.common.viewdo.SelectOption;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.common.entity.EducationEntity;
import io.renren.modules.common.service.EducationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author nyc
 * @email 2691778746@qq.com
 * @date 2022-03-13 15:36:11
 */
@RestController
@RequestMapping("common/education")
public class EducationController {
    @Autowired
    private EducationService educationService;

    @Autowired
    private EducationDao educationDao;

    @GetMapping("/select-option")
    public R selectOptionStruct(){
        List<EducationEntity> educationEntities = educationDao.selectList(null);
        List<SelectOption> optionList = educationEntities.stream().map(item -> new SelectOption(item.getId().toString(), item.getEducationName())).collect(Collectors.toList());
        return R.ok().put("data",optionList);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("common:education:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = educationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("common:education:info")
    public R info(@PathVariable("id") Integer id){
		EducationEntity education = educationService.getById(id);

        return R.ok().put("education", education);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("common:education:save")
    public R save(@RequestBody EducationEntity education){
		educationService.save(education);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("common:education:update")
    public R update(@RequestBody EducationEntity education){
		educationService.updateById(education);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("common:education:delete")
    public R delete(@RequestBody Integer[] ids){
		educationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
